/*
 * @Descripttion: your project
 * @version: 1.0
 * @Author: hongweixun
 * @Date: 2022-05-31 08:24:47
 * @LastEditors: liyin 2179253556@qq.com
 * @LastEditTime: 2023-02-18 10:12:58
 */
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
// import HomeView from '../views/HomeView.vue'
import Login from '@/views/Login.vue'
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'login',
    meta: {
      keetAlive: true
    },
    component: Login
  },
  {
    path: '/',
    redirect: 'index'
  },
  {
    path: '/home',
    name: 'home',
    meta: {
      title: '课室巡检',
      keetAlive: false
    },
    component: () => import('@/views/home.vue')
  },
  {
    path: '/homeView',
    name: 'homeView',
    meta: {
      title: '点名统计',
      keetAlive: false
    },
    component: () => import('@/views/HomeView.vue')
  },
  {
    path: '/index',
    name: 'index',
    meta: {
      title: '课堂点名',
      keetAlive: true
    },
    component: () => import('@/views/index.vue')
  },
  {
    path: '/login',
    name: 'login',
    meta: {
      title: '登录',
      keetAlive: true
    },
    component: Login
  },
  {
    path: '/managerRecord',
    name: 'managerRecord',
    meta: {
      title: '班级点名',
      keetAlive: false
    },
    component: () => import('@/components/ManagerRecord.vue')
  },
  {
    path: '/record',
    name: 'record',
    meta: {
      title: '查看记录',
      keetAlive: false
    },
    component: () => import('@/components/Record.vue')
  },
  {
    path: '/classRecord',
    name: 'classRecord',
    meta: {
      title: '异常名单',
      keetAlive: false
    },
    component: () => import('@/components/ClassRecord.vue')
  },
  {
    path: '/dormitory',
    name: 'Dormitory',
    meta: {
      title: '异常名单',
      keetAlive: false
    },
    component: () => import('@/components/Dormitory.vue')
  },
  // 班级统计详情
  {
    path: '/classMessage',
    name: 'classMessage',
    meta: {
      title: '年级统计详情'
    },
    component: () => import('@/components/ClassMessage.vue')
  },
  // 个人统计详情
  {
    path: '/userMessage',
    name: 'userMessage',
    meta: {
      title: '个人统计详情'
    },
    component: () => import('@/components/UserMessage.vue')
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior() {
    // 始终滚动到顶部
    return { top: 0 }
  }
})
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title as any
  }
  // const appeal = window.sessionStorage.getItem('is_appeal')
  // if (from.path === '/index' && Number(appeal) === 1) {
  //   setTimeout(() => {
  //     window.location.reload()
  //   }, 300)
  // }
  next()
})
export default router
